package com.tjjingpan.fragementtest

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.fragment.app.Fragment
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.leftfragment.*

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
//        //通过按钮切换Fragment
//        button.setOnClickListener {
//            replaceFragment(AnotherRightFragment())
//        }
//        replaceFragment(RightFragemnt())
    }

//    private fun replaceFragment(fragment: Fragment) {
//        //获取FragmentManager
//        val fragmentManager = supportFragmentManager
//        //开启一个事务
//        val transaction = fragmentManager.beginTransaction()
//        transaction.replace(R.id.rightLayout, fragment)
//        //添加到返回栈中
//        transaction.addToBackStack(null)
//        transaction.commit()
//    }

    private fun testGetFragment() {
        //从布局文件中获取Fragment实例
        val fragment = supportFragmentManager.findFragmentById(R.id.leftFrag) as LeftFragment
        //kotlin-andorid-extensions插件方法获取Fragment
        val fragemnt = leftFrag as LeftFragment
    }
}